//
//  ThemeChoiceViewController.m
//  weibo-01
//
//  Created by HZApple on 16/5/10.
//  Copyright © 2016年 hdu. All rights reserved.
//

#import "ThemeChoiceViewController.h"
#import "ThemeChoiceTableViewCell.h"
#import "ThemeChoiceModel.h"
#import "ThemeManager.h"

@interface ThemeChoiceViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) NSMutableArray *dataArray;


@end

@implementation ThemeChoiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UITableView *tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64)  style:UITableViewStylePlain];
    tableview.delegate = self;
    tableview.dataSource = self;
    UIColor *backColor = [[ThemeManager sharedManager] themeColorWithColorName:@"More_Item_color"];
    tableview.backgroundColor = backColor;
    [self.view addSubview:tableview];
    
    [self loaddata];
    
    [tableview registerClass:[ThemeChoiceTableViewCell class] forCellReuseIdentifier:@"123"];
    
    // Do any additional setup after loading the view.
}

- (void)loaddata {
    
    _dataArray = [NSMutableArray array];
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Theme" ofType:@"plist"]];
    NSArray *array = [dic allKeys];
    for (int i = 0; i < array.count; i++) {
        ThemeChoiceModel *model = [[ThemeChoiceModel alloc] init];
        model.imageName = @"more_icon_theme";
        model.themeColorName = @"More_Item_Text_color";
        model.themeName = array[i];
        model.themePath = [dic objectForKey:array[i]];
        [_dataArray addObject:model];
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ThemeChoiceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"123" forIndexPath:indexPath];
    
    cell.model = _dataArray[indexPath.row];
    
    if ([[ThemeManager sharedManager].themeName isEqualToString:[_dataArray[indexPath.row] themeName]]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ThemeManager *manager =  [ThemeManager sharedManager];
    manager.themeName = [_dataArray[indexPath.row] themeName];
    UIColor *backColor = [[ThemeManager sharedManager] themeColorWithColorName:@"More_Item_color"];
    tableView.backgroundColor = backColor;
    [tableView reloadData];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
